package com.itheima.wms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.wms.common.service.CrudServiceImpl;
import com.itheima.wms.common.utils.RelationUtils;
import com.itheima.wms.dao.*;
import com.itheima.wms.entity.GoodsEntity;
import com.itheima.wms.entity.LocationEntity;
import com.itheima.wms.service.GoodsService;
import com.itheima.wms.vo.GoodsDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 业务实现类
 * 货品管理
 * </p>
 */
@Slf4j
@Service
public class GoodsServiceImpl extends CrudServiceImpl<GoodsMapper, GoodsEntity> implements GoodsService {

    private static List<Class> SERVICE = new ArrayList() {{
        add(StockMapper.class);
        add(ReceiptListMapper.class);
    }};

    @Override
    public IPage<GoodsDetailVO> pageDetail(Page<GoodsDetailVO> page, Map data) {
        IPage<GoodsDetailVO> iPage = this.baseMapper.selectGoodsDetail(page, data);
        return iPage;
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        idList.forEach(id -> {
            RelationUtils.checkRelation(id, "goods_id", SERVICE);
        });
        return super.removeByIds(idList);
    }
}

